using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using NorthStar.Passenger.Application;
using TheNorthStar.Api.Requests;
using TheNorthStar.Api.Results;

namespace NorthStar.Passenger
{
    public class RateDriverAsync : AsyncTask
    {
        private readonly Context _context;
        private RateDriverRequest _request;
        private ProgressDialog p;

        public RateDriverAsync(Context context, RateDriverRequest request)
        {
            _context = context;
            _request = request;
        }

        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            var api = new ApiService(Helper.GetServer(_context));

            return api.RateDriver(_request);
        }


        protected override void OnPostExecute(Java.Lang.Object result)
        {
            base.OnPostExecute(result);
            
            var res = Newtonsoft.Json.JsonConvert.DeserializeObject<GeneralResult>(result.ToString());
            string message = "";
            if (res.Success)
            {
                message = "Rating recieved. Thanks for your feedback";
            }
            else
            {
                message = "We did not correctly receive your rating. Please try later.";
            }

            Toast.MakeText(_context, message, ToastLength.Short).Show();

        }
    }
}